<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
			
			for(let value of arr){
				console.log(value);
			}
			debugger

			var even = arr.map(function(x) {
				return x * x;
			});
			even = arr.map(n => n * n);
			console.log(even);

			var sortResult = arr.sort(function(a, b) {
				return b - a;
			});
			sortResult = arr.sort((a, b) => b - a);
			console.log(sortResult);

			function Foo() {
				this.id = 100;
				console.log("foo", this); //Foo 当前对象
				let _this = this; //使用变量_this存储当前遍历的实例
				setTimeout(function() {
					console.log("setTimeout", this.id, _this.id, this); //window
				});
			}

			//let f1 = new Foo();

			function Moo() {
				this.id = 100;
				console.log("Moo", this); //Moo
				setTimeout(() => {
					console.log("setTimeout", this.id, this); //Moo
				});
			}
			//let m1 = new Moo();
			
			let User={
				id:1001,
				getFun:function(){
					console.log(this);
				}
			}
			
			User.getFun(); //当前对象
			
			//Xoo是一个对象,直接作为全局变量声明.等价于在window中声明
			let Xoo={
				id:1001,
				getFun:()=>{
					console.log(this); //window
				}
			}
			Xoo.getFun();
			
			
			
		</script>
	</body>
</html>
